<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<!DOCTYPE html>
<html>
<head>
    <title></title>

    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <!-- 引入bootstrap -->
    <link rel="stylesheet" type="text/css" href="/css/bootstrap.min.css">
    <!-- 引入JQuery  bootstrap.js-->
    <script src="/js/jquery-3.2.1.min.js"></script>
    <script src="/js/bootstrap.min.js"></script>
</head>
<body>
<!-- 顶栏 -->
<jsp:include page="top.jsp"></jsp:include>
<!-- 中间主体 -->
<div class="container" id="content">
    <div class="row">
        <jsp:include page="menu.jsp"></jsp:include>
        <div class="col-md-10">
            <div class="panel panel-default">
                <div class="panel-heading">
                    <div class="row">
                        <h1 style="text-align: center;">用户列表</h1>
                    </div>
                </div>
                <div class="panel-body">
                    <table class="table table-bordered">
                        <thead>
                        <tr>
                            <th>用户ID</th>
                            <th>用户名</th>

                            <th>操作</th>
                        </tr>
                        </thead>
                        <tbody id="table">


                        </tbody>

                    </table>
                </div>

            </div>

        </div>
    </div>
</div>
<div class="container" id="footer">
    <div class="row">
        <div class="col-md-12"></div>
    </div>
</div>
</body>
<script>
    $("#nav li:nth-child(7)").addClass("active")
    $(function () {
        $.ajax({
            url:"/user/list?limit=100&page=1",
            method:"post",
            dataType:"json",
            success:function (data) {

                for (var i=0;i<data.data.list.length;i++){
                    var text="<tr><td>"+data.data.list[i].userID+"</td> <td>"+data.data.list[i].username+"</td><td><input id='"+data.data.list[i].userID+"' type='hidden' value='"+data.data.list[i].userID+"'><a href='javascript:'>删除</a></td>"
                    $("#table").append(text)
                    var id=data.data.list[i].userID;
                    $("#"+data.data.list[i].userID).next("a").click(function () {


                        var msg = "您真的确定要删除吗？！";
                        if (confirm(msg)==true) {
                            $.ajax({
                                url: '/user/'+id,
                                type: 'delete',
                                success: function () {
                                    alert("删除成功")
                                    window.location.href = "userlist";

                                },
                                error: function () {
                                    alert("删除失败")
                                }
                            })
                        }else {

                        }
                    })

                }
            }


        })
    })


</script>
</html>